// Problem 062: Cubic permutations
// Find the smallest cube for which exactly five permutations of its digits are cube.
package main

import (
	"fmt"
	"projecteuler/euler"
)

func p062() {
	var m map[string]int = make(map[string]int)
	var target string
	x := 5000
	for {
		x++
		cube := x * x * x
		digits := 0
		for cube > 0 {
			d := cube % 10
			digits += euler.IntPow(10, d)
			cube /= 10
		}
		key := fmt.Sprintf("%d", digits)
		if v, ok := m[key]; ok {
			m[key] = v + 1
		} else {
			m[key] = 1
		}
		if m[key] == 5 {
			target = key
			break
		}
	}
	x = 5000
	for {
		x++
		cube := x * x * x
		digits := 0
		for cube > 0 {
			d := cube % 10
			digits += euler.IntPow(10, d)
			cube /= 10
		}
		key := fmt.Sprintf("%d", digits)
		if key == target {
			fmt.Println("Problem 062:", x*x*x)
			break
		}
	}
}
